cmake_minimum_required(VERSION 3.10)
project(lidar2cam_fusion)
add_definitions(-w)
add_definitions(-std=c++14)
add_definitions(-DAPI_EXPORTS)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 14)
# set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  rospy
  sensor_msgs

  message_filters
  pcl_conversions
  pcl_ros

  detect_msgs
)


catkin_package()

include_directories(${catkin_INCLUDE_DIRS})


# TODO(Call for PR): make cmake compatible with Windows
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
# set(CMAKE_CUDA_COMPILER /usr/local/cuda-10/bin/nvcc)
enable_language(CUDA)

# cuda
include_directories(/usr/local/cuda/include)
link_directories(/usr/local/cuda/lib64)

# include_directories(/usr/local/cuda-10/include)
# link_directories(/usr/local/cuda-10/lib64)

# tensorrt
include_directories(/home/lin/code/TensorRT-8.2.1.8/include/)
link_directories(/home/lin/code/TensorRT-8.2.1.8/lib/)

include_directories(${PROJECT_SOURCE_DIR}/include/)


file(GLOB_RECURSE SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp
                        ${PROJECT_SOURCE_DIR}/src/*.cu)

file(GLOB_RECURSE FUSION_SRC ${PROJECT_SOURCE_DIR}/fusion_src/*.cpp)      

set(CUSTOM_MSGS detect_msgs)   # 自定义数据类型文件目录

# ------------生成库-----------------    
# file(GLOB_RECURSE PLUGIN_SRCS ${PROJECT_SOURCE_DIR}/plugin/*.cu)
# add_library(myplugins SHARED ${PLUGIN_SRCS})
# target_link_libraries(myplugins nvinfer cudart)
# ------------生成库----------------- 

#-------------nano-------------
set(OpenCV_DIR /home/agilex/software/opencv-3.4.16/build)

# set(OpenCV_DIR /usr/share/OpenCV/OpenCVConfig.cmake)

find_package(OpenCV 3.0 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

include_directories(/usr/local/include/eigen3)
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})

# set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

# add_library(mydettensorrt SHARED ${SRCS} ${FUSION_SRC})
# add_dependencies(mydettensorrt ${${PROJECT_NAME}_EXPORTTED_TARGETS} ${catkin_EXPORTED_TARGETS}  ${PROJECT_NAME}_generate_messages_cpp)
# target_link_libraries(mydettensorrt nvinfer cudart ${PCL_LIBRARIES} ${OpenCV_LIBS} )

#----------------

# add_executable(detector_camera test/detector_camera.cpp ${SRCS})
# target_link_libraries(detector_camera nvinfer cudart ${OpenCV_LIBS} ${catkin_LIBRARIES} )


add_executable(detect_node test/only_detect_node.cpp ${SRCS} )
add_dependencies(detect_node ${CUSTOM_MSGS}_generate_messages_cpp)
target_link_libraries(detect_node ${OpenCV_LIBS} ${catkin_LIBRARIES} nvinfer cudart )

add_executable(min_distance_node test/min_distance_node.cpp ${SRCS}  ${FUSION_SRC})
add_dependencies(min_distance_node ${catkin_EXPORTED_TARGETS} ${CUSTOM_MSGS}_generate_messages_cpp)
target_link_libraries(min_distance_node nvinfer cudart ${OpenCV_LIBS} ${PCL_LIBRARIES} ${catkin_LIBRARIES})

add_executable(xyz2rgb_node test/xyz2rgb_node.cpp ${SRCS}  ${FUSION_SRC})
add_dependencies(min_distance_node ${catkin_EXPORTED_TARGETS} ${CUSTOM_MSGS}_generate_messages_cpp)
target_link_libraries(xyz2rgb_node nvinfer cudart ${OpenCV_LIBS} ${PCL_LIBRARIES} ${catkin_LIBRARIES})


MESSAGE("\n------------\n\n----OPENCV VERSION: " ${OpenCV_VERSION})
MESSAGE("----PCL VERSION: " ${PCL_VERSION})
MESSAGE("----CUDA VERSION: " ${CUDA_VERSION})
MESSAGE("----TensorRT VERSION: " ${TensorRT_FOUND})
message("\n---------------\n")